<?php
class Controller
{
    protected $view=null;
	
	public function __construct()
	{
	    $this->view=new View();
	}
	
	public function assign($var,$value='')
	{
	    $this->view->assign($var,$value);
	}
	
	public function display($file)
	{
	    $this->view->display($file);
	}
	
    public function Run()
	{
	    $this->Analysis();
		$control=$_GET['c'];
		$action=$_GET['a'];
		
		$controlFile=ROOT_PATH.'/Controllers/'.$control.'class.php';
		if(!file_exists($controlFile))
		    exit($controlFile .'is not exist');
		
		include($controlFile);
		$class=ucwords($control);
		if(!class_exists($class))
		    exit($class .' is not exist');
		$instance=new $class();
		if(!method_exists($instance,$action))
		    exit($action .' is not exist');
		$instance->$action();
	}
	
	/**
	*����url��ÿ�������action
	*/
	protected function Analysis()
	{
	    global $config;
		if($config['URL_MODE']==1)
		{
		    $control=!empty($_GET['c']) ? trim($_GET['c']) : '';
			$action=!empty($_GET['a']) ? trim($_GET['a']) : '';
		}
		else if($config['URL_MODE']==2)
		{
		    if(isset($_SERVER['PAHT_INFO']))
			{
			    $path=trim($_SERVER['PATH_INFO'],'/');
				$paths=explode('/',$path);
				$control=array_shift($paths);
				$action=array_shift($paths);
			}
		}
		
		$_GET['c']=$control=!empty($control) ? $control : $config['DEFAULT_CONTROL'];
		$_GET['a']=$action=!empty($action) ? $action : $config['DEFAULT_ACTION'];
	}
	
	
}

?>